package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmMaterialDto;
import com.heima.wemedia.entity.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class MaterialController {



    @Autowired
    private WmMaterialService materialService;
    /**
     * 上传图片
     * @param multipartFile
     * @return
     */
    @PostMapping("/api/v1/material/upload_picture")
    public ResponseResult<String> upload(MultipartFile multipartFile){

        return ResponseResult.ok(materialService.upload(multipartFile));
    }


    @PostMapping("/api/v1/material/list")
    public PageResult<WmMaterial> findByPage(@RequestBody WmMaterialDto dto){

        return materialService.findByPage(dto);

    }
    @DeleteMapping("/api/v1/material/del_picture/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){

        materialService.deleteById(id);
        return ResponseResult.ok();
    }

}
